/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.text_text.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.text_text.entity.TextText;
import com.thinkgem.jeesite.modules.text_text.service.TextTextService;

/**
 * 测试用Controller
 * @author ZhaoHai
 * @version 2017-07-02
 */
@Controller
@RequestMapping(value = "${adminPath}/text_text/textText")
public class TextTextController extends BaseController {

	@Autowired
	private TextTextService textTextService;
	
	@ModelAttribute
	public TextText get(@RequestParam(required=false) String id) {
		TextText entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = textTextService.get(id);
		}
		if (entity == null){
			entity = new TextText();
		}
		return entity;
	}
	
	@RequiresPermissions("text_text:textText:view")
	@RequestMapping(value = {"list", ""})
	public String list(TextText textText, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<TextText> page = textTextService.findPage(new Page<TextText>(request, response), textText); 
		model.addAttribute("page", page);
		return "modules/text_text/textTextList";
	}

	@RequiresPermissions("text_text:textText:view")
	@RequestMapping(value = "form")
	public String form(TextText textText, Model model) {
		model.addAttribute("textText", textText);
		return "modules/text_text/textTextForm";
	}

	@RequiresPermissions("text_text:textText:edit")
	@RequestMapping(value = "save")
	public String save(TextText textText, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, textText)){
			return form(textText, model);
		}
		textTextService.save(textText);
		addMessage(redirectAttributes, "保存测试用成功");
		return "redirect:"+Global.getAdminPath()+"/text_text/textText/?repage";
	}
	
	@RequiresPermissions("text_text:textText:edit")
	@RequestMapping(value = "delete")
	public String delete(TextText textText, RedirectAttributes redirectAttributes) {
		textTextService.delete(textText);
		addMessage(redirectAttributes, "删除测试用成功");
		return "redirect:"+Global.getAdminPath()+"/text_text/textText/?repage";
	}
    /**
     *随便添加100条数据 
     * 
     */
	@RequestMapping(value = "addtexts")
	public void addtext() {
		System.out.println("进入方法");
		textTextService.adddatas();
	}
}